package com.wx.plugin.mvc;

import com.wx.plugin.sms.holder.SMSHolder;
import com.wx.plugin.util.StringUtil;
import io.github.elkan1788.mpsdk4j.api.WechatAPI;
import io.github.elkan1788.mpsdk4j.common.EventType;
import io.github.elkan1788.mpsdk4j.vo.api.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloworldController {

    @Autowired
    private WechatAPI wechatAPI;

    @Autowired
    private SMSHolder smsHolder;


    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "hello world!";
    }

    @RequestMapping("/test/createMenu")
    @ResponseBody
    String createMenu() {
        Menu menu = new Menu();
        menu.setName("玫瑰谷商城");
        menu.setUrl("http://mp.weixin.qq.com/bizmall/mallshelf?id=&t=mall/list&biz=MzA5MTMyOTY2NQ==&shelf_id=1&showwxpaytitle=1#wechat_redirect");
        menu.setType(StringUtil.lowerObjectString(EventType.VIEW));
        return String.valueOf(wechatAPI.createMenu(menu));
    }

    @RequestMapping("/test/deleteMenu")
    @ResponseBody
    String deleteMenu() {
        return String.valueOf(wechatAPI.delMenu());
    }

    @RequestMapping("/test/sms")
    @ResponseBody
    String sms() {
        smsHolder.sendSMS("18559161957", "杨宙", "哈哈");
        return "success";
    }

}
